package com.dindang.ddm.mvp.ui.adapter.multitype;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dindang.ddm.R;
import com.dindang.ddm.app.AppConst;
import com.dindang.ddm.mvp.model.entity.Repairs;
import com.dindang.ddm.mvp.ui.listener.MyOnClickListener;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class RepairListViewBinder extends ItemViewBinder<Repairs.RepairList, RepairListViewBinder.ViewHolder> {

    MyOnClickListener listener;

    public RepairListViewBinder(MyOnClickListener mListener) {
        listener = mListener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_repair_list, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Repairs.RepairList repairList) {
        holder.mTvTime.setText(repairList.billdate);
        holder.mTvStatus.setText(repairList.state);
        holder.mTvName.setText(repairList.contacts);
        holder.mTvAddress.setText(repairList.address);
        if("".equals(repairList.regiontype) || repairList.regiontype == null){
            holder.mTvRepairArea.setText(repairList.region);
        }else{
            holder.mTvRepairArea.setText(repairList.region + ": " + repairList.regiontype);
        }

        holder.mTvRepairContent.setText(repairList.content);

        holder.mConstraintlayout.setOnClickListener(v -> listener.onClick(holder.getAdapterPosition()));
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ConstraintLayout mConstraintlayout;
        TextView mTvTime;
        TextView mTvStatus;
        TextView mTvName;
        TextView mTvAddress;
        TextView mTvRepairArea;
        TextView mTvRepairContent;
        ViewHolder(View itemView) {
            super(itemView);
            mConstraintlayout = itemView.findViewById(R.id.constraintlayout);
            mTvTime = itemView.findViewById(R.id.tvTime);
            mTvStatus = itemView.findViewById(R.id.tvStatus);
            mTvName = itemView.findViewById(R.id.tvName);
            mTvAddress = itemView.findViewById(R.id.tvAddress);
            mTvRepairArea = itemView.findViewById(R.id.tvRepairArea);
            mTvRepairContent = itemView.findViewById(R.id.tvRepairContent);
        }
    }

}
